﻿Imports System.Data.OleDb
Imports BUS
Imports DTO

Public Class frmDangNhap
    Public kqDangNhap As Boolean = False

    Public Function KT_DangNhap() As Boolean
        Dim tenDangNhap As String = txtTenDangNhap.Text
        Dim matKhau As String = txtMatKhau.Text

        '  Dim loaiNhanVien As Integer= NhanVienBus.LayNguoiDangNhap(tenDangNhap, matKhau)

        Dim dt As DataTable = NhanVienBus.LayNguoiDung(tenDangNhap, matKhau)
        If (dt.Rows.Count = 0) Then
            Return False
        End If

        sessionNhanVien.MaNhanVien = dt.Rows(0).Item("MaNhanVien")
        sessionNhanVien.LoaiNhanVien = dt.Rows(0).Item("LoaiNhanVien")

        Return True
        'Try
        '    If loaiNhanVien <> -1 Then
        '        ' MessageBox.Show("Đăng nhập thành công !", "Thông báo", MessageBoxButtons.OK)
        '        Return True
        '    End If
        'Catch ex As Exception
        '    '.....
        'End Try

        'Return False
    End Function

    Private Sub btnDangNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangNhap.Click
        kqDangNhap = KT_DangNhap()
        If kqDangNhap Then

            Close()
        Else
            txtMatKhau.Text = ""
            MessageBox.Show("Nhập sai tên hoặc mật khẩu!", "Thông báo", MessageBoxButtons.OK)
        End If
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub frmDangNhap_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        txtTenDangNhap.Text = ""
        txtMatKhau.Text = ""
    End Sub

    Private Sub frmDangNhap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class